package org.orion.engine;

import java.awt.AWTException;
import java.awt.Cursor;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;

import org.orion.engine.math.Vector2i;
import org.orion.engine.math.Vector3d;

public class CameraFly extends Camera {
	public double fi,ksi;
	
	
	public double sizeStep;
	public double sizeAngle;
	
	
	
	public CameraFly(){
		init();
		changeCenterUp();
	}
	
	private void init(){
		position = new Vector3d(0.0, 10.0, 0.0);
		center = new Vector3d(0.0, 0.0, 0.0);
		up = new Vector3d( 0.0, 1.0, 0.0);
		fi=0;
		ksi=Math.PI;
		sizeStep=1.0;
		sizeAngle=Math.PI/360.0;
	}
	
	private void changeCenterUp()
	{
		center.x=position.x+ Math.sin(fi)*Math.sin(ksi);
		center.z=position.z+Math.cos(fi)*Math.sin(ksi);
		center.y=position.y+Math.cos(ksi);
		up.x=-Math.sin(fi)*Math.cos(ksi);
		up.z=-Math.cos(fi)*Math.cos(ksi);
		up.y=Math.sin(ksi);
	}

	public void forward()
	{
		position.x=position.x+sizeStep*Math.sin(fi)*Math.sin(ksi);
		position.z=position.z+sizeStep*Math.cos(fi)*Math.sin(ksi);
		position.y=position.y+sizeStep*Math.cos(ksi);
		changeCenterUp();
	}

	public void back()
	{
		position.x=position.x-sizeStep*Math.sin(fi)*Math.sin(ksi);
		position.z=position.z-sizeStep*Math.cos(fi)*Math.sin(ksi);
		position.y=position.y-sizeStep*Math.cos(ksi);
		changeCenterUp();
	}

	public void left()
	{
		position.x=position.x+sizeStep*Math.cos(fi);
		position.z=position.z-sizeStep*Math.sin(fi);
		changeCenterUp();
	}

	public void right()
	{
		position.x=position.x-sizeStep*Math.cos(fi);
		position.z=position.z+sizeStep*Math.sin(fi);
		changeCenterUp();
	}

	public void rotateUpDown(int count)
	{
		double temp=ksi+count*sizeAngle;
		if (temp>0 & temp<Math.PI) ksi=temp;
		changeCenterUp();
	}

	public void rotateLeftRight(int count)
	{
        fi=fi-count*sizeAngle;
		if (fi>Math.PI*2) fi-=Math.PI*2;
		changeCenterUp();
	}
	
	
	
}
